package com.wut.redis.lock.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.integration.redis.util.RedisLockRegistry;

/**
 * Redis分布式锁配置类
 */
@Configuration
@ComponentScan(value = "com.wut.redis.lock")
@ConditionalOnClass(RedisConnectionFactory.class)
public class RedisLockConfig {

    @Bean
    @ConditionalOnMissingBean
    public RedisLockRegistry redisLockRegistry(RedisConnectionFactory redisConnectionFactory) {
        return new RedisLockRegistry(redisConnectionFactory, "lock", 5 * 60 * 1000);
    }
}
